bitkeeper revision 1.1159.1.1 (41137be7CbsfIV_H_aLlq3moTPnDwA)
authorkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Fri, 6 Aug 2004 12:39:03 +0000 (12:39 +0000)
committerkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Fri, 6 Aug 2004 12:39:03 +0000 (12:39 +0000)
Ensure binary patches are applied only to private VMAs.

linux-2.6.7-xen-sparse/arch/xen/kernel/fixup.c

index 55384af25ffdeef9dfb46b8356f1abcf6453947d..61c5497f400c08a17565b95108bffbef166ace5c 100644 (file)
@@ -409,6 +409,22 @@ asmlinkage void do_fixup_4gb_segment(struct pt_regs *regs, long error_code)
     *(unsigned long *)&patch[1] = 
         (fixup_buf_user + fe->fixup_idx) - (eip + 5);
 
+    /*
+     * Check that the page to be patched is part of a read-only VMA. This 
+     * means that our patch will never erroneously get flushed to disc.
+     */
+    if ( eip < PAGE_OFFSET ) /* don't need to check the fixmap area */
+    {
+        /* [SMP] Need to the mmap_sem semaphore. */
+        struct vm_area_struct *vma = find_vma(current->mm, eip);
+        if ( (vma == NULL) || (vma->vm_flags & VM_MAYSHARE) )
+        {
+            DPRINTK("Cannot patch a shareable VMA.");
+            return;
+        }
+    }
+
+    /* [SMP] Need to pause other threads while patching. */
     pgd = pgd_offset(current->mm, eip);
     pmd = pmd_offset(pgd, eip);
     pte = pte_offset_kernel(pmd, eip);